import { getUsers } from '@/api/user'
const state = {
  usersList: [],
  total: 0
}

const mutations = {
  CHANGE_USERLIST (state, usersList) {
    state.usersList = usersList
  },
  CHANGE_TOTAL (state, total) {
    state.total = total
  }
}

const actions = {
  async getUserList ({commit}, queryInfo) {
    const data = await getUsers(queryInfo)
    if (data.meta.status !== 200) return this.$message('获取用户列表失败')
    commit('CHANGE_USERLIST', data.data.users)
    commit('CHANGE_TOTAL', data.data.total)
  }
}

export default {
  state,
  mutations,
  actions
}
